/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.bibliotecaDao;

import mx.its.dsw2.biblioteca.Modelo.Libro;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Yessy
 */
@Stateless
public class LibroDao extends AbstractDao<Libro> implements LibroDaoLocal {
    @PersistenceContext(unitName = "Biblioteca8e-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public LibroDao() {
        super(Libro.class);
    
    }
    
    @Override
     public boolean findDuplicity(Libro book){
       
        Query q=em.createNamedQuery("Libro.findByClave");
       q.setParameter("clave", book.getClave());
        
        return !q.getResultList().isEmpty();
    
    }

    @Override
    public Libro findBookForLend(String claveLibro) {
       Query q=em.createNamedQuery("Libro.findByClave");
       q.setParameter("clave", claveLibro);
       if(!q.getResultList().isEmpty()){
           return (Libro)q.getResultList().get(0);
       }else{
        
        return null;
       }
    }
     
}
